package com.lx.util.secure.algorithm.coder;

import com.lx.annotation.Note;
import com.lx.util.secure.Algorithm;

import java.nio.charset.StandardCharsets;

public class StringCoder implements Coder {

    private StringCoder(){}
    private static final StringCoder SC = new StringCoder();
    public static StringCoder getCoder(){
        return SC;
    }

    @Override
    public byte[] encode(byte[] bytes) {
        return bytes;
    }

    @Override
    public byte[] encode(String data) {
        return data.getBytes(StandardCharsets.UTF_8);
    }

    @Override
    public String encodeToString(byte[] bytes) {
        return new String(bytes,StandardCharsets.UTF_8);
    }

    @Override
    public String encodeToString(String data) {
        return data;
    }

    @Override
    public byte[] decode(byte[] bytes) {
        return bytes;
    }

    @Override
    public byte[] decode(String data) {
        return data.getBytes(StandardCharsets.UTF_8);
    }

    @Override
    public String decodeToString(byte[] bytes) {
        return new String(bytes,StandardCharsets.UTF_8);
    }

    @Override
    public String decodeToString(String data) {
        return data;
    }
}
